# -*- coding: UTF-8 -*-
"""
@Project ：swift-forge-engine 
@File    ：orera_log_service.py
@IDE     ：PyCharm 
@Author  ：Tony.Gan
@Date    ：2025/2/22 21:35 
@Des     ：
"""
from sqlalchemy import Select
from fastapi import Request

from App.app.admin.crud.opera_log_crud import OperaLogDao
from App.app.admin.schemas.opera_log_schema import CreateOperaLogParam
from App.common.security.jwt import superuser_verify
from App.database.mysql import async_db_session


class OperaLogServices:
    @staticmethod
    async def get_select(*, username: str | None = None, status: str | None = None, ip: str | None = None,
                         sort_field: str | None = None, sort_order: str | None = None) -> Select:
        return await OperaLogDao.get_list(username=username, status=status, ip=ip, sort_field=sort_field,
                                          sort_order=sort_order)

    @staticmethod
    async def create(*, obj_in: CreateOperaLogParam):
        async with async_db_session.begin() as db:
            await OperaLogDao.create(db, obj_in)

    @staticmethod
    async def delete(*, request: Request, pk: list[int]) -> int:
        async with async_db_session.begin() as db:
            superuser_verify(request)
            count = await OperaLogDao.delete(db, pk)
            return count

    @staticmethod
    async def delete_all(request: Request) -> int:
        async with async_db_session.begin() as db:
            superuser_verify(request)
            count = await OperaLogDao.delete_all(db)
            return count


OperaLogService: OperaLogServices = OperaLogServices()
